package com.ruoyi.common.enums;

import com.ruoyi.common.constant.GameConst;

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public interface GameEnum {
    enum GameTypeEnum {

        WINGO(1,"wingo"),

        PICK3(2,"pick3");

        // 类型
        private Integer type;
        // 描述
        private String desc;

        GameTypeEnum(int type,String desc){
            this.type = type;
            this.desc = desc;
        }

        public static GameTypeEnum get(int type){
            for(GameTypeEnum gameTypeEnum : GameTypeEnum.values()){
                if(gameTypeEnum.getType() == type){
                    return gameTypeEnum;
                }
            }
            return null;
        }

        public Integer getType() {
            return type;
        }

        public String getDesc() {
            return desc;
        }
    }

    enum TimeLimitEnum {
        ONE_MINUTE(60,1,"60秒"),

        THREE_MINUTE(180,3,"180秒"),

        FIVE_MINUTE(300,5,"300秒"),
        ;

        // 时间
        private Integer time;
        // 分
        private Integer minute;
        // 描述
        private String desc;

        static Map<Integer, TimeLimitEnum> map = new HashMap<>();

        static {
            for(TimeLimitEnum timeLimitEnum : TimeLimitEnum.values()){
                map.put(timeLimitEnum.getTime(),timeLimitEnum);
            }
        }

        TimeLimitEnum(int time,int minute,String desc){
            this.time = time;
            this.desc =desc;
            this.minute = minute;
        }

        public Integer getTime() {
            return time;
        }

        public Integer getMinute() {
            return minute;
        }

        public String getDesc() {
            return desc;
        }

        public static TimeLimitEnum getTimeLimitEnum(int time){
            return map.get(time);
        }
    }

    enum PlayTypeGroupEnum {
        COLOR(GameConst.TYPE_GROUP_COLOR),
        SMALLBIG(GameConst.TYPE_GROUP_SMALLBIG),
        NUM(GameConst.TYPE_GROUP_NUM);

        private Integer type;

        private static Map<Integer, PlayTypeGroupEnum> map = new HashMap<>();

        static {
            for(PlayTypeGroupEnum playTypeGroupEnum : PlayTypeGroupEnum.values()){
                map.put(playTypeGroupEnum.getType(),playTypeGroupEnum);
            }
        }

        PlayTypeGroupEnum(int type){
            this.type = type;
        }

        public Integer getType() {
            return type;
        }

        public static PlayTypeGroupEnum get(int type) {
            return map.get(type);
        }
    }

    enum PlayType{
        RED(1, GameConst.TYPE_GROUP_COLOR,"red"),
        VIOLET(2,GameConst.TYPE_GROUP_COLOR,"violet"),

        GREEN(3,GameConst.TYPE_GROUP_COLOR,"green"),

        BIG(4,GameConst.TYPE_GROUP_SMALLBIG,"big"),

        SMALL(5,GameConst.TYPE_GROUP_SMALLBIG,"small"),

        NUMBER(6,GameConst.TYPE_GROUP_NUM,"number");
        // 类型
        Integer type;
        // 分组
        private Integer groupType;
        // 描述
        String desc;

        static Map<Integer, List<PlayType>> groupList = new HashMap<>();

        static Map<Integer, PlayType> cache = new HashMap<>();

        static {
            groupList = Arrays.stream(PlayType.values()).collect(Collectors.groupingBy(PlayType::getGroup));
            cache = Arrays.stream(PlayType.values()).collect(Collectors.toMap(PlayType::getType, v -> v));
        }

        PlayType(Integer type,Integer groupType,String desc)
        {

            this.type = type;
            this.groupType = groupType;
            this.desc = desc;
        }

        public Integer getType()
        {
            return this.type;
        }

        public Integer getGroup() {
            return this.groupType;
        }

        public String getDesc(){
            return this.desc;
        }

        public static List<PlayType> getColorGroup(){
            return groupList.get(GameConst.TYPE_GROUP_COLOR);
        }

        public static List<PlayType> getSmallbigGroup(){
            return groupList.get(GameConst.TYPE_GROUP_SMALLBIG);
        }

        public static List<PlayType> getNumGroup(){
            return groupList.get(GameConst.TYPE_GROUP_NUM);
        }

        public static PlayType getWingo(Integer type){
            return cache.get(type);
        }
    }

    enum Ball{
        ZERO("0",2,4,"零号"),
        ONE("1",3,4,"一号"),
        TWO("2",1,4,"二号"),
        THREE("3",3,4,"三号"),
        FOUR("4",1,4,"四号"),
        FIVE("5",2,5,"五号"),
        SIX("6",1,5,"六号"),
        SEVEN("7",3,5,"七号"),
        EIGHT("8",1,5,"八号"),
        NINE("9",3,5,"九号");

        // 类型
        private String value;
        // 颜色类型
        private int playTypeColor;
        // 大小类型
        private int playTypeSmallBig;
        // 描述
        private String desc;

        static Map<String, Ball> cache = new HashMap<>();

        static {
            for(Ball ball : Ball.values()){
                cache.put(ball.getValue(),ball);
            }
        }

        Ball(String value,int playTypeColor,int playTypeSmallBig,String desc){
            this.value = value;
            this.desc = desc;
            this.playTypeColor = playTypeColor;
            this.playTypeSmallBig = playTypeSmallBig;
        }

        public static BigDecimal getColorMulX(Ball openBall,int playType){
            // 颜色一样
            if(openBall.getPlayTypeColor() == playType){
                return WinMulX.get(playType).getMulX();
            }
            // 开红色和0号
            if(PlayType.RED.getType() == playType && ZERO.getValue().equals(openBall.getValue())){
                return WinMulX.HALF_COLOR.getMulX();
            }
            // 开绿色和5号
            if(PlayType.GREEN.getType() == playType && FIVE.getValue().equals(openBall.getValue())){
                return WinMulX.HALF_COLOR.getMulX();
            }
            return BigDecimal.ZERO;
        }

        public static BigDecimal getSmallBigMulX(Ball openBall,int playType){
            if(openBall.getPlayTypeSmallBig() == playType){
                return WinMulX.get(playType).getMulX();
            }
            return BigDecimal.ZERO;
        }

        public static BigDecimal getNumMulX(Ball openBall,String yourBallNo){
            if(openBall.getValue().equals(yourBallNo)){
                return WinMulX.NUMBER.getMulX();
            }
            return BigDecimal.ZERO;
        }

        public static BigDecimal getPick3MulX(String aBallNo,String bBallNo,String cBallNo,
                                String youraBallNo,String yourbBallNo,String yourcBallNo){
            String arrBall[] = {aBallNo,bBallNo,cBallNo};
            String yourArrBall[] = {youraBallNo,yourbBallNo,yourcBallNo};
            int count = 0;
            for(int i = 0 ; i < arrBall.length ; i++){
                if(!arrBall[i].equals(yourArrBall[i])){
                    continue;
                }
                count++;
            }
            if(count <= 0){
                return BigDecimal.ZERO;
            }
            return WinMulX.get(7+count).getMulX();
        }

        public String getValue() {
            return value;
        }

        public int getPlayTypeColor() {
            return playTypeColor;
        }

        public int getPlayTypeSmallBig() {
            return playTypeSmallBig;
        }

        public String getDesc() {
            return desc;
        }

        public static Ball get(String value) {
            return cache.get(value);
        }
    }

    // 奖励倍数
    enum WinMulX{
        RED(1,new BigDecimal("2")),
        VIOLET(2,new BigDecimal("4.5")),
        GREEN(3,new BigDecimal("2")),
        BIG(4,new BigDecimal("2")),
        SMALL(5,new BigDecimal("2")),
        NUMBER(6,new BigDecimal("9")),
        // 半色
        HALF_COLOR(7,new BigDecimal("1.5")),
        // 匹配一个
        MATCH_ONE(8,new BigDecimal("1.3")),
        // 匹配两个
        MATCH_TWO(9,new BigDecimal("12")),
        // 匹配三个
        MATCH_THREE(10,new BigDecimal("200"));
        // 类型
        private Integer playType;
        // 倍数
        private BigDecimal mulX;

        static Map<Integer, WinMulX> cache = new HashMap<>();

        static {
            for(WinMulX winMulX : WinMulX.values()){
                cache.put(winMulX.getPlayType(),winMulX);
            }
        }

        WinMulX(int playType,BigDecimal mulX){
            this.playType = playType;
            this.mulX = mulX;
        }

        public Integer getPlayType() {
            return playType;
        }

        public BigDecimal getMulX() {
            return mulX;
        }

        public static WinMulX get(int playType) {
            return cache.get(playType);
        }
    }
}
